/**
 * 专案管理UI
 * @class ProjectTreeGrid
 * @extends Ext.ux.tree.TreeGrid
 */
ProjectTreeGrid = Ext.extend(Ext.ux.tree.TreeGrid, {
	assignOwnerWindow: null,
	win_copyModel: null,
	constructor: function(config){
		Ext.apply(this, config);
		
		var win_create_project;
		var win_edit_project;
				
		ProjectTreeGrid.superclass.constructor.call(this, {
			id: 'project_tree_grid',
			width: 600,
			height: 300,
			border: false,
			enableDD: false,
			autoScroll: true,
			viewConfig: {forceFit: true},
	        columns:[{
	            header: "文件名称",
	            width: 350,
	            dataIndex: 'name'
	        },{
	            header: "负责人",
	            width: 130,
	            dataIndex: 'owner'
	        },{
	            header: "状态",
	            width: 85,
	            dataIndex: 'status',
	            tpl: new Ext.XTemplate('{[this.colorStatus(values.status)]}', {
					colorStatus: function(v) {
						if(v == "[500]On-Going") return "<font color=blue>"+v+"</font>";
		            	else if(v == "[100]Unstarted") return "<font color=gray>"+v+"</font>";
		            	else if(v == "[910]Closed"||v == "[900]Released") return "<font color=green>"+v+"</font>";
		            	else if(v == "[800]Delayed") return "<font color=red>"+v+"</font>";
		            	else return v;
					}
				})
	        },{
	            header: "版本",
	            width: 40,
	            dataIndex: 'version'
	        },{
	            header: "申请日期",
	            width: 70,
	            dataIndex: 'dateOfOrder'
	        },{
	            header: "发行日期",
	            width: 70,
	            dataIndex: 'dateOfEffect'
	        },{
	            header: "备注",
	            width: 260,
	            dataIndex: 'memo'
	        }],
	        dataUrl: '/pdm/category/asyncNewCateTreeGrid.htm',
	        root: new Ext.tree.AsyncTreeNode({
	        	id: '40',
	            text: "root"
	        }),
	        tbar: [{
	        	id: 'btn_Create_Project',
	        	text: "新建",
	        	scope: this,
	        	iconCls: 'cls_add_to_category',
	        	handler: function(){
	        		var cur_node = this.getSelectionModel().getSelectedNode();
	        		var sortOrder = cur_node.childNodes.length+1;
	        		
	        		if( !cur_node ){
	        			Ext.Msg.alert("提示","请先选择目标目录！")
	        		}else{
		        		var catePath = getCatePathName(cur_node);
		        		
	        			if(!win_create_project){
	        				win_create_project = new CreateProjectWin({id:'createProjectWin', _parentId: cur_node.id});
	        			} else {
		        			win_create_project.reset();
		        			win_create_project.setParentId(cur_node.id);
	        			}
	        			win_create_project.setCatePath(catePath);
	        			win_create_project.setSortOrder(sortOrder);
	        			win_create_project.show();
	        		}
	        	}
	        },{
	        	id: 'btn_Edit_Project',
	        	text: "编辑",
	        	iconCls: 'cls_edit_project',
	        	handler: function(){
	        		var cur_node_id = document.getElementById("_selected_project_id").value;
	        		if(cur_node_id == ""){
	        			Ext.Msg.alert("提示","请选择需要编辑的目录");
	        		}else{
        				jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
						try{
							var info = jsonrpc.jabsorbService.getEditCateInfo(cur_node_id);
						}catch(e){
							alert(e);
						}
						var jsonInfo = eval("("+info+")");
					
						if(!win_edit_project)
						{
							win_edit_project = new EditProjectWin({node_info: jsonInfo});
						}
						
						win_edit_project.reset();
						win_edit_project.setValue(jsonInfo);
						
						win_edit_project.show();
	        		}
	        	}
	        },{
	        	id: 'btn_Remove_Project',
	        	text: "删除",
	        	scope: this,
	        	iconCls: 'cls_remove_cate',
	        	tooltip: "删除选中的节点",
	        	handler: function(){
	        		var cur_node_id = document.getElementById("_selected_project_id").value;
	        		
	        		if(cur_node_id == ""){
	        			Ext.Msg.alert("提示：","请选择需要删除的目录!");
	        		}else{
	        			var selectedItem = this.getSelectionModel().getSelectedNode();
						var json = selectedItem.toJsonString(null,
							function(key, val) {
								return (key == 'name'|| key == 'owner'|| key == 'status');
							}, {
								name: 'text',
								owner: 'owner',
								status: 'status'
							}
						);
						//alert(json);
		        		var obj = eval("("+json+")");
		        		Ext.MessageBox.show({
							title: "温馨提示：",
							msg: "您确认要删除["+obj.text+"]节点？",
							buttons: Ext.MessageBox.YESNO,
							fn: function(btn){
								if(btn == "yes")
								{
									var delMask = new Ext.LoadMask(Ext.getBody(), {
										msg: "信息删除中，请稍后...",
										removeMask: true
									});
									delMask.show();
									
									Ext.Ajax.request({
										url: '/pdm/category/deleteCate.htm',
										method: 'post',
										params: {
											cate_id: cur_node_id
										},
										success: function(response,options){
											/*
											var result = Ext.decode(response.responseText).message;
											Ext.Msg.alert("信息:", renderString(result));
											*/
											delMask.hide();
											
											var tg_project = Ext.getCmp("project_tree_grid");
											var parent_node = tg_project.getSelectionModel().getSelectedNode().parentNode;
											parent_node.reload(this);
										},
										failure: function(response){
											var result = Ext.decode(response.responseText).message;
											Ext.Msg.alert("信息:", result);
										}
									});
								}
								else return;
							}
						});
					}
	        	}
	        },"-",{
	        	id: 'btn_Copy_Template',
	        	text: "模板复制",
	        	iconCls: 'cls_copy_template',
	        	tooltip: "按模板创建下面的文档类型",
	        	scope: this,
	        	handler: function(){
	        		//var cur_node_id = document.getElementById("_selected_project_id").value;
	        		var selectedItem = this.getSelectionModel().getSelectedNode();
	        		
	        		if(Ext.isEmpty(selectedItem))
	        		{
	        			Ext.Msg.alert("提示","请选择需要从模板复制的目标节点");
	        		}else{
	        			var json = selectedItem.toJsonString(null,
							function(key, val) {
								return (key == 'name'|| key == 'owner'|| key == 'status');
							}, {
								name: 'text',
								owner: 'owner',
								status: 'status'
							}
						);
		        		var obj = eval("("+json+")");
	        			
	        			if(!Ext.isEmpty(this.win_copyModel))
	        			{
	        				this.win_copyModel.destroy()
	        			}
	        			
	        			this.win_copyModel = new CopyProjectWin({id: "win_copyTemplate", targetName: obj.text});
	        			
	        			this.win_copyModel.setTargetName(obj.text);
	        			this.win_copyModel.show();
	        		}
	        		
	        		/*
	        		if(selectedItem.childNodes.length == 0){
		        		var json = selectedItem.toJsonString(null,
							function(key, val) {
								return (key == 'name'|| key == 'owner'|| key == 'status');
							}, {
								name: 'text',
								owner: 'owner',
								status: 'status'
							}
						);
		        		var obj = eval("("+json+")");
		        		
		        		Ext.MessageBox.show({
							title: "温馨提示：",
							msg: "您确认从文档结构模板创建新的类型结构到["+obj.text+"]节点下？",
							buttons: Ext.MessageBox.YESNO,
							fn: function(btn){
								if(btn == "yes")
								{
									var copyMask = new Ext.LoadMask(Ext.getBody(), {
										msg: "模板复制中，请稍后...",
										removeMask: true
									});
									copyMask.show();
									
									Ext.Ajax.request({
										url: '/pdm/category/copyFromTemplate.htm',
										method: 'post',
										params: {
											target_id: selectedItem.id
										},
										success: function(response, options){
											
											copyMask.hide();
											
											var project_tree_grid = Ext.getCmp("project_tree_grid");
											var parent_node = project_tree_grid.getNodeById(cur_node_id).parentNode;
							        		project_tree_grid.loader.load(parent_node);
											parent_node.expand(true,true);
										},
										failure: function(response, options){
											var result = Ext.decode(response.responseText).message;
											Ext.Msg.alert("信息:", result);
										}
									});
								}
								else return;
							}
						});
	        		}else{
	        			for(var i=0;i<selectedItem.childNodes.length;i++)
	        			{
	        				var childNode = selectedItem.childNodes[i];
	        				
	        				var child = childNode.toJsonString(null,
								function(key, val) {
									return (key == 'name');
								}, {
									name: 'text'
								}
							);
			        		var objChild = eval("("+child+")");
	        				
	        				if(objChild.text=="EVT"||objChild.text=="DVT"||objChild.text=="PVT"||objChild.text=="NPRB")
	        				{
	        					Ext.Msg.alert("提示:","模板已存在。");
	        					break;
	        				}else{
	        					Ext.Msg.alert("提示:","请选择正确的阶段下创建模板。");
	        					break;
	        				}
	        			}
	        		}
	        		*/
	        	}
	        },"-",{
	        	id: 'btn_Owner_Assign',
	        	text: "负责人设置",
	        	scope: this,
	        	iconCls: 'cls_assign_owner',
	        	tooltip: "对项目设置相应的负责人",
	        	handler: function(){
	        		var cur_node = this.getSelectionModel().getSelectedNode();
	        		if(!cur_node)
	        		{
	        			Ext.Msg.alert("提示","请先选择相应的项目.");
	        		}else{
		        		var json = cur_node.toJsonString(null,
							function(key, val) {
								return (key == 'name'|| key == 'owner'|| key == 'status');
							}, {
								name: 'text',
								owner: 'owner',
								status: 'status'
							}
						);
		        		var obj = eval("("+json+")");
		        		
		        		if(!cur_node){
		        			Ext.Msg.alert("温馨提示：","请先选择需要设定的项目！");
		        		}else{
		        			var members = getProjectOwnerList(cur_node.id);
		        			Ext.fly("_collectReCosign").dom.value = members;
		        			
		        			if(!this.assignOwnerWindow){
		        				this.assignOwnerWindow = new AssignOwnerWindow({id:'assignOnwerWin'});
		        			}
		        			this.assignOwnerWindow.setTitle("对["+obj.text+"]设定负责人");
		        			this.assignOwnerWindow.assignOwnerPanel.objReCosignSelect.setReCosigners(members);
		        			this.assignOwnerWindow.reDoLayout();
			        		this.assignOwnerWindow.show();
			        		
			        		this.assignOwnerWindow.assignOwnerPanel.objReCosignSelect.load();
						}
	        		}
	        	}
	        },"-",{
	        	id: 'btn_Start_Project',
	        	text: "启动项目",
	        	scope: this,
	        	iconCls: 'cls_open_project',
	        	tooltip: "开启项目，负责人进行维护相应的表单",
	        	handler: function(){
	        		var cur_node = this.getSelectionModel().getSelectedNode();
	        		
	        		if(!cur_node){
	        			Ext.Msg.alert("提示：","请先选择目标目录!");
	        		}else{
	        			var selectedItem = this.getSelectionModel().getSelectedNode();
						var json = selectedItem.toJsonString(null,
							function(key, val) {
								return (key == 'name'|| key == 'owner'|| key == 'status');
							}, {
								name: 'text',
								owner: 'owner',
								status: 'status'
							}
						);
		        		var obj = eval("("+json+")");
		        		
		        		Ext.MessageBox.show({
							title: "温馨提示：",
							msg: "您确认要启动项目["+obj.text+"]吗？",
							buttons: Ext.MessageBox.YESNO,
							fn: function(btn){
								if(btn == "yes") handleProject(cur_node.id, 'open');
								else return;
							}
						});
					}
	        	}
	        },{
	        	id: 'btn_Restore_Project',
	        	text: "暂停项目",
	        	scope: this,
	        	iconCls: 'cls_close_project',
	        	tooltip: "暂停已启动的项目",
	        	handler: function(){
	        		var cur_node = this.getSelectionModel().getSelectedNode();
	        		
	        		if(!cur_node){
	        			Ext.Msg.alert("提示：","请先选择目标目录!");
	        		}else{
						var json = cur_node.toJsonString(null,
							function(key, val) {
								return (key == 'name'|| key == 'owner'|| key == 'status');
							}, {
								name: 'text',
								owner: 'owner',
								status: 'status'
							}
						);
		        		var obj = eval("("+json+")");
		        		
		        		if(obj.status == "[910]Closed"){
		        			Ext.Msg.alert("请注意：","已经完成的项目不可以停止！");
		        		}else{
			        		Ext.MessageBox.show({
								title: "温馨提示：",
								msg: "您确认要暂停项目["+obj.text+"]？",
								buttons: Ext.MessageBox.YESNO,
								fn: function(btn){
									if(btn == "yes") handleProject(cur_node.id, 'close');
									else return;
								}
							});
		        		}
					}
	        	}
	        },"->",{
	        	text: "刷新",
	        	tooltip: "刷新本表格窗口",
	        	iconCls: "cls_table_refresh",
	        	scope: this,
	        	handler: function(){
	        		this.root.reload(true,true);
	        	} 
	        }]
		});
		
		this.on('click',function(node){
			document.getElementById("_selected_project_id").value = node.id;
			
			if(node.isLeaf()){
				Ext.getCmp("btn_Create_Project").disable();
				Ext.getCmp("btn_Edit_Project").disable();
				Ext.getCmp("btn_Remove_Project").disable();
				Ext.getCmp("btn_Copy_Template").disable();
				//Ext.getCmp("btn_Owner_Assign").enable();
				Ext.getCmp("btn_Start_Project").disable();
				Ext.getCmp("btn_Restore_Project").disable();
			}else{
				if(node.getDepth()<5){
					if(node.getDepth()!=4) Ext.getCmp("btn_Create_Project").enable();
					Ext.getCmp("btn_Edit_Project").enable();
					Ext.getCmp("btn_Remove_Project").enable();
				}else{
					Ext.getCmp("btn_Create_Project").disable();
					Ext.getCmp("btn_Edit_Project").disable();
					Ext.getCmp("btn_Remove_Project").disable();
				}
				if(node.getDepth()==4){
					Ext.getCmp("btn_Copy_Template").enable();
					Ext.getCmp("btn_Create_Project").disable();
				}else{
					Ext.getCmp("btn_Copy_Template").disable();
				}
				//Ext.getCmp("btn_Owner_Assign").enable();
				Ext.getCmp("btn_Start_Project").enable();
				Ext.getCmp("btn_Restore_Project").enable();
			}
	    });
	    
	    this.on('dblclick',function(node){
			document.getElementById("_selected_project_id").value = node.id;
			
			if(node.isLeaf()){
				var selectedItem = this.getSelectionModel().getSelectedNode();
				var json = node.toJsonString(null,
					function(key, val) {
						return (key == 'mastId'|| key == 'tmplId'|| key == 'owner');
					}, {
						mastId: 'mastId',
						tmplId: 'tmplId',
						owner: 'owner'
					}
				);
	       		var obj = eval("("+json+")");
	       		
	       		if(obj.tmplId == 0) Ext.Msg.alert("提示","无法开启，表单尚未分配模板，请联系管理员!");
	       		else if(obj.mastId == 0) Ext.Msg.alert("提示","表单无法打开，请联系管理员！");
	       		else 
	       		//window.open("AutoCreate.jsp?mast_id="+obj.mastId+"&tmpl_id="+obj.tmplId);
	       		window.open(window.basePath + "/form.htm?method=show&mast_id="+obj.mastId);
			}
			
	    });
	    
	    this.on('contextmenu',function(node, e){
			/*
			node.select();
			var c = new Ext.menu.Menu({
				items: [{
					text: 'Add Node'
				}],
				listeners: {
					itemclick: function(item) {
							alert(node.id);
						}
			    }
			});
			c.showAt(e.getXY());
			*/
	    });
	}
});

/**
 * 开启或关闭项目
 * @param {} cateId
 * @param {} action 处理类型，'open','close'
 */
function handleProject(cateId, action){
	Ext.Ajax.request({
		url: window.basePath + '/project.htm?method=handle',
		method: 'post',
		params: {
			cate_id: cateId,
			action: action
		},
		success: function(response, options){
			var project_tree_grid = Ext.getCmp("project_tree_grid");
			var cur_node = project_tree_grid.getSelectionModel().getSelectedNode();
			cur_node.parentNode.reload(true,true);
		},
		failure: function(response){
			var result = Ext.decode(response.responseText).message;
			Ext.Msg.alert("信息:", result);
		}
	});
}

/****************************************************
 * @class CreateProjectWin
 * @extends Ext.Window
 ***************************************************/
	CreateProjectWin = Ext.extend(Ext.Window,{
		projectPanel: null,
		_parentId: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.projectPanel = new CreateProjectPanel({_parentId:this._parentId});
			
			CreateProjectWin.superclass.constructor.call(this, {
				layout: 'fit',
				title: "[专案管理]:  新建",
				width: 380,
				height: 250,
				resizable: false,
				modal: true,
				closeAction: 'hide',
				plain: true,
				buttonAlign: 'right',
				items: this.projectPanel,
				buttons: [{
					text: "保存",
					disabled: false,
					handler: function(){
						var p = Ext.getCmp("createProjectPanel");
						
						if( p.getForm().isValid() ) 
						{
							p.form.submit({
								url	 : '/pdm/category/createProject.htm',
								success : function(form,action)
								{
									var tg_project = Ext.getCmp("project_tree_grid");
									
									tg_project.getSelectionModel().getSelectedNode().reload();
									/*
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：",obj.message);
									*/
																		
									var w = Ext.getCmp("createProjectWin");
									w.hide();
								},
								failure : function(form, action) 
								{
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：",obj.message);
									
									var w = Ext.getCmp("createProjectWin");
									w.hide();
								},
								waitMsg : '数据保存中，请等待...'
							});
						}else{
							Ext.Msg.alert('温馨提示', '红色框为必填项!');
						}  
					}
				},{
					text: "关闭",
					scope: this,
					handler: function(){
						this.hide();
					}
				}]
			});
		},
		reset: function()
		{
			this.projectPanel.form.reset();
		},
		setParentId: function(c){
			this.projectPanel.form.setValues({
				"parent_id": c
			})
		},
		setCatePath: function(path){
			this.projectPanel.form.setValues({
				"cate_path": path
			})
		},
		setSortOrder: function(c){
			this.projectPanel.form.setValues({
				"sort_order": c
			})
		}
	});

/****************************************************
 * @class CreateProjectPanel
 * @extends Ext.FormPanel
 ***************************************************/
	CreateProjectPanel = Ext.extend(Ext.FormPanel,{
		_parentId: null,
		constructor: function(config){
		
			Ext.apply(this,config);
			
			CreateProjectPanel.superclass.constructor.call(this, {
				labelWidth: 55,
				id: 'createProjectPanel',
				frame: true,
				border: false,
				bodyStyle: 'padding:5px 5px 5px 5px',
				defaultType: 'textfield',
				items:[{
					fieldLabel: "路径",
					name: 'cate_path',
					allowBlank: false,
					readOnly: true,
					msgTarget: 'side',
					anchor: '90%',
					value: ''
				},{
					fieldLabel: "名称",
					name: 'cate_name',
					allowBlank: false,
					maxLength: 100,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '90%',
					value: ''
				},{
					xtype: 'numberfield',
					fieldLabel: "排列序号",
					name: 'sort_order',
					allowBlank: false,
					msgTarget: 'side',
					anchor: '40%',
					value: '9999'
				},{
					xtype: 'textarea',
					fieldLabel: "备注",
					name: 'memo',
					allowBlank: true,
					maxLength: 150,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '89%',
					value: ''
				},{
					id: 'parent_id',
					name: 'parent_id',
					hidden: true,
					value: this._parentId
				},{
					id: 'cate_type',
					name: 'cate_type',
					hidden: true,
					value: 'F'
				}]
			});
		}
	});

/****************************************************
 * @class AssignOwnerWindow
 * @extends Ext.Window
 ***************************************************/
AssignOwnerWindow = Ext.extend(Ext.Window,{
	assignOwnerPanel: null,
	constructor: function(config){
		Ext.apply(this,config);
		
		this.assignOwnerPanel = new ReCosignPanel();
		
		AssignOwnerWindow.superclass.constructor.call(this, {
			layout: 'form',
			width: 640,
			height: 480,
			closeAction: 'hide',
			plain: true,
			modal: true,
			buttonAlign: 'center',
			resizable: false,
			layout: 'fit',
			items: [this.assignOwnerPanel],
			buttons: [{
			    text: "确定",
			    disabled: false,
			    scope: this,
			    handler: function(){
			    	var ownersList = Ext.fly("_collectReCosign").dom.value;
			    	var cur_node_id = Ext.fly("_selected_project_id").dom.value;
			    	
			    	var strMsg = "正在保存，请稍后...";
			    	if(ownersList=="") strMsg = "正在清除负责人，请稍后...";
			    	
			    	var saveMask = new Ext.LoadMask(Ext.getBody(), {
						msg: strMsg,
						removeMask: true
					});
					saveMask.show();
			    	
		    		Ext.Ajax.request({
						url: '/pdm/category/saveProjectOwners.htm',
						method: 'post',
						params: {
							owners: ownersList,
							projectId: cur_node_id
						},
						success: function(response,options){
							var treegrid = Ext.getCmp("project_tree_grid");
							
							var parent_node = treegrid.getNodeById(cur_node_id).parentNode;
							treegrid.loader.load(parent_node);
							parent_node.expand(true,true);
							
							saveMask.hide();
							/*
							var obj = Ext.decode(response.responseText).message;
							Ext.Msg.alert("info",obj);
							*/
						},
						failure: function(response){
							var obj = Ext.decode(response.responseText).message;
							Ext.Msg.alert("error",obj);
						}
					});
			    	this.hide();
			    }
			},{
			    text: "关闭",
			    disabled: false,
			    scope: this,
			    handler: function(){
			    	this.hide();
			    }
			}]
		});
	},
	reset: function(){
		this.assignOwnerPanel.reset();
	},
	reDoLayout: function(){
		var tbpnl = Ext.getCmp("tbpnl_recosign_list");
		tbpnl.setActiveTab(0);
		this.assignOwnerPanel.tree.root.reload(true,true);
	}
});

/****************************************************
 * @class EditProjectWin
 * @extends Ext.Window
 ***************************************************/
	EditProjectWin = Ext.extend(Ext.Window,{
		editProjectPanel: null,
		node_info: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.editProjectPanel = new EditProjectPanel({cur_node_info: this.node_info});
			
			EditProjectWin.superclass.constructor.call(this, {
				id: 'editProjectWin',
				layout: 'fit',
				title: "[专案管理]:  编辑",
				width: 380,
				height: 250,
				resizable: false,
				modal: true,
				closeAction: 'hide',
				plain: true,
				buttonAlign: 'right',
				items: this.editProjectPanel,
				buttons: [{
					text: "保存",
					disabled: false,
					handler: function(){
					
						var p = Ext.getCmp("editProjectPanel");
						
						if( p.getForm().isValid() ) 
						{
							p.form.submit({
								url	 : '/pdm/category/editProject.htm',
								success : function(form,action)
								{
									/*
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：",obj.message);
									
									var tp_cate_model = Ext.getCmp("tp_category_model");
									tp_cate_model.root.reload();
									tp_cate_model.root.expand(true,true);
									*/								
									var tg_project = Ext.getCmp("project_tree_grid");
									tg_project.getSelectionModel().getSelectedNode().parentNode.reload();
									
									var w = Ext.getCmp("editProjectWin");
									w.hide();
								},
								failure : function(form, action) 
								{
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：",obj.message);
								},
								waitMsg : '请等待...'
							});
						}else{
							Ext.Msg.alert('温馨提示', '红色框为必填项!');
						}  
					}
				},{
					text: '关闭',
					handler: function(){
						var w = Ext.getCmp("editProjectWin");
						w.hide();
					}
				}]
			});
		},
		reset: function()
		{
			this.editProjectPanel.form.reset();
		},
		setValue: function(value)
		{
			this.editProjectPanel.form.setValues({
				"cate_name": value.cate_name,
				"sort_order": value.sort_order,
				"memo": value.memo,
				"cate_id": value.cate_id
			});
		}
	});
/****************************************************
 * @class EditProjectPanel
 * @extends Ext.FormPanel
 ***************************************************/
	EditProjectPanel = Ext.extend(Ext.FormPanel,{
		cur_node_info: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			EditProjectPanel.superclass.constructor.call(this, {
				labelWidth: 55,
				id: 'editProjectPanel',
				frame: true,
				border: false,
				bodyStyle: 'padding:5px 5px 5px 5px',
				defaultType: 'textfield',
				items:[{
					fieldLabel: "名称",
					id: 'cate_name',
					name: 'cate_name',
					allowBlank: false,
					maxLength: 100,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '90%',
					value: this.cur_node_info ? this.cur_node_info.cate_name:""
				},{
					xtype: 'numberfield',
					fieldLabel: "排列序号",
					name: 'sort_order',
					id: 'sort_order',
					allowBlank: false,
					maxLength: 4,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '40%',
					value: this.cur_node_info ? this.cur_node_info.sort_order:""
				},{
					xtype: 'textarea',
					fieldLabel: "备注",
					name: 'memo',
					id: 'memo',
					allowBlank: true,
					maxLength: 150,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '89%',
					value: this.cur_node_info ? this.cur_node_info.memo:""
				},{
					id: 'cate_id',
					name: 'cate_id',
					hidden: true,
					value: this.cur_node_info ? this.cur_node_info.cate_id:""
				},{
					id: 'cate_type',
					name: 'cate_type',
					hidden: true,
					value: 'F'
				}]
			});
		}
	});	

/****************************************************
 * @class CopyProjectWin
 * @extends Ext.Window
 ***************************************************/
	CopyProjectWin = Ext.extend( Ext.Window, {
		pnl_id: null,
		targetName: null,
		constructor: function(config){
			Ext.apply(this, config);
			
			if(this.pnl_id==null) this.pnl_id = Ext.id();
			
			CreateProjectWin.superclass.constructor.call(this, {
				title: "您正在使用[模板复制]功能",
				layout: 'fit',
				width: 380,
				height: 220,
				modal: true,
				plain: true,
				border: true,
				resizable: false,
				autoDestroy: true,
				closeAction: 'hide',
				buttonAlign: 'right',
				items: [{
					id: 'fp_copyTemplate',
					xtype: 'panel',
					labelWidth: 55,
					frame: false,
					border: false,
					layout: 'form',
					bodyStyle: 'padding: 5px 5px 5px 5px',
					items: [{
						id: this.pnl_id,
						xtype: 'panel',
						frame: false,
						border: false,
						anchor: '90%',
						html: "请在下面选择框中选择需要复制的模板，选择完毕后点击保存，系统将会将模板复制到您已选择的目标节点[<b><font color=red>"+this.targetName+"</font></b>]下<br/><br/><br/>"
					},{
						xtype: 'combo',
						fieldLabel: "模板名称",
						id: 'combo_all_model',
						name: 'combo_all_model',
						forceSelection: true,
						store: new Ext.data.JsonStore({
							url: '/pdm/category/getAllModel.htm',
							totalProperty: 'totalProperty',
							root: 'root',
							fields: ['key','name']
						}),
						valueField: 'key',
						displayField: 'name',
						emptyText: "请选择模板...",
						loadingText: "正在加载所有模板",
						typeAhead: true,
						mode: 'remote',
						anchor: '90%',
						editable: false,
						triggerAction: 'all',
						selectOnFocus: true,
						listeners: {
						    select: function(combo, record, index) {
								var model_id = record.data.key;
								Ext.fly("model_id").dom.value = model_id;
							}
						}
					},{
						xtype: 'hidden',
						value: '-1',
						hidden: true,
						name: 'model_id'
					}]
				}],
				buttons: [{
					text: "复制",
					scope: this,
					handler: function(){
						var project_tree = Ext.getCmp("project_tree_grid");
						var cur_node = project_tree.getSelectionModel().getSelectedNode();
						
						if(Ext.fly("combo_all_model").dom.value == "请选择模板..."||Ext.fly("combo_all_model").dom.value == "")
						{
							Ext.Msg.alert("提示","请选择需要复制的模板");
						}else{
							var copyMask = new Ext.LoadMask(Ext.getBody(), {
								msg: "模板复制中，请稍后...",
								removeMask: true
							});
							copyMask.show();
							
							Ext.Ajax.request({
								url: '/pdm/category/copyFromTemplate.htm',
								method: 'post',
								params: {
									target_id: cur_node.id,
									model_id: Ext.fly("model_id").dom.value
								},
								success: function(response, options){
									var win = Ext.getCmp("win_copyTemplate");
									win.hide();
									
									copyMask.hide();
									
									var project_tree_grid = Ext.getCmp("project_tree_grid");
									var parent_node = cur_node.parentNode;
					        		project_tree.loader.load(parent_node);
									parent_node.expand(true,true);
								},
								failure: function(response, options){
									var result = Ext.decode(response.responseText).message;
									Ext.Msg.alert("信息:", result);
								}
							});
						}
					}
				},{
					text: "关闭",
					scope: this,
					handler: function(){
						this.hide();
					}
				}]
			});
		},
		setTargetName: function(c){
			this.targetName = c;
		},
		reDoLayout: function(){
			Ext.getCmp(this.pnl_id);
		}
	});
	